package com.markerhub.controller;


import com.markerhub.common.ResponseJson;
import com.markerhub.entity.Link;
import com.markerhub.entity.Message;
import com.markerhub.mapper.MessageMapper;
import com.markerhub.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 关注公众号：MarkerHub
 * @since 2021-04-10
 */
@Api(value = "MessageController",tags = "博客留言接口")
@RestController
@RequestMapping("/message")
public class MessageController {
    @Autowired
    MessageService messageService;

    @ApiOperation(value = "增加留言")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "time",value = "时间",required = true,dataType = "string"),
            @ApiImplicitParam(name = "messageContent",value = "留言内容",required = true,dataType = "string"),
            @ApiImplicitParam(name = "avatar",value = "头像链接",required = true,dataType = "string"),
            @ApiImplicitParam(name = "nickname",value = "昵称",required = true,dataType = "string"),
    })
    @PostMapping("/addMessage")
    public Object addLink(String time,String messageContent,String avatar,String nickname){
        try{
            messageService.addMessage(time,messageContent,avatar,nickname);
            return ResponseJson.success();
        }catch (Exception e)
        {
            return ResponseJson.failure(e.getMessage());
        }
    }

    @ApiOperation(value = "获取留言信息")
    @GetMapping("/MessageList")
    public Object getLinkList(){
        List<Message> messages=messageService.getMessageList();
        try{
            return ResponseJson.success(messages);
        }catch (Exception e)
        {
            return ResponseJson.failure(e.getMessage());
        }
    }
}
